<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
    <script src="js/vue-router.js"></script>
    <style>
        li {
            list-style: none;
            margin: 20px 10px;
            display: inline-block;
        }

        a {
            text-decoration: none;
        }

        .show {
            width: 300px;
            height: 200px;
            background-color: #ccc;
        }
    </style>
</head>

<body>
    <div id="box">
        <nav>
            <ul>
                <li><router-link to='/home'>home</router-link></li>
                <li><router-link to='/news'>news</router-link></li>
                <li><router-link to='/hot'>hot</router-link></li>
            </ul>
            <div class="show">
                <router-view></router-view>
            </div>
        </nav>
    </div>
</body>

</html>
<script>
    //由内而外，把路由一个一个部分来写
    //1.创建组件
    var Home=Vue.extend({template:'<h1>首页</h1>'});
    var News={template:'<h1>新闻</h1>'};
    var Hot={template:'<h1>热门</h1>'};

    //2.创建路径
     var routes=[
        {path:'/home',component:Home},
        {path:'/news',component:News},
        {path:'/hot',component:Hot},
     ];

     //3.创建路由对象
     var router=new VueRouter({
         routes:routes
     })

    var vm=new Vue({
        el:"#box",
        data:{},
        //4.配置路由
        router:router

    })

</script>